import { Module } from 'vuex'
import { IRootState } from '../types'
import { ISystemState } from './types'
import { getPageListData } from '@/service/main/system'
import { IResponseResult } from '@/service/request/type'

const systemModule: Module<ISystemState, IRootState> = {
  namespaced: true,
  state() {
    return {
      userList: [],
      userCount: 0
    }
  },
  mutations: {
    changeUserList(state, userList: any[]) {
      state.userList = userList
      state.userCount = userList.length
    }
  },
  actions: {
    async getPageListAction({ commit }, payload: any) {
      console.log('请求 getPageListAction 的参数：', payload)

      const url = payload.pageUrl
      const queryInfo = payload.queryInfo

      // getPageListData(url, queryInfo)
      //   .then((res) => {
      //     console.log('请求来的表格数据：', res)
      //   })
      //   .catch((err) => {
      //     console.log('请求表格数据出现异常：', err)
      //   })
      const res: IResponseResult = await getPageListData(url, queryInfo)
      commit('changeUserList', res.data)
      console.log('请求用户数据响应来的结果：', res)
    }
  }
}

export { systemModule }
